<?php

namespace addons\helper;

use app\common\library\Menu;
use think\Addons;

/**
 * 插件
 */
class Helper extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'helper',
                'title'   => 'FastAdmin助手',
                'icon'    => 'fa fa-flash',
                'sublist' => [
                    [
                        "name"  => "helper/user",
                        "title" => "用户管理",
                        'icon'    => 'fa fa-user',
                        'sublist' => [
                            ['name' => 'helper/user/index', 'title' => '查看'],
                            ['name' => 'helper/user/edit', 'title' => '编辑'],
                            ['name' => 'helper/user/del', 'title' => '删除'],
                            ['name' => 'helper/user/multi', 'title' => '批量更新'],
                        ]
                    ],
                    [
                        "name"  => "helper/userlog",
                        "title" => "用户日志管理",
                        "icon"  => "fa fa-list-alt",
                        'sublist' => [
                            ['name' => 'helper/userlog/index', 'title' => '查看'],
                            ['name' => 'helper/userlog/edit', 'title' => '编辑'],
                            ['name' => 'helper/userlog/del', 'title' => '删除'],
                            ['name' => 'helper/userlog/multi', 'title' => '批量更新'],
                        ]
                    ],
                    [
                        "name"  => "helper/menu",
                        "title" => "菜单管理",
                        "icon"  => "fa fa-th",
                        'sublist' => [
                            ['name' => 'helper/menu/index', 'title' => '查看'],
                            ['name' => 'helper/menu/multi', 'title' => '批量更新'],
                        ]
                    ],
                    [
                        "name"  => "helper/generator",
                        "title" => "一键生成工具",
                        "icon"  => "fa fa-file-code-o",
                        'sublist' => [
                            ['name' => 'helper/generator/index', 'title' => '生成'],
                        ]
                    ]
                ]
            ]
        ];
        Menu::create($menu);
        // 默认启用系统核心菜单和助手菜单
        $sysMenuIds = [2,3,4,5,6,7,8,9,10,11,12,66,67,73,79];
        $helperMenuIds = Menu::getAuthRuleIdsByName('helper');
        set_addon_config('helper', ['MenuList'=> array_merge($sysMenuIds,$helperMenuIds)]);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('helper');
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable('helper');
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable('helper');
        return true;
    }

}
